﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace XNAGame_Lab1
{
    public class MySprites2D : MyObject
    {

        private Vector2 _Size= new Vector2(0,0);

        public Vector2 Size
        {
            get { return _Size; }
            set { _Size = value; }
        }
        /// <summary>
        /// bitmap
        /// </summary>
        
        private Texture2D[] _Textures;


        public Texture2D[] Textures
        {
            get { return _Textures; }
            set { _Textures = value;
            nTextures = Textures.Length;
            iTextures = 0;
            }
        }
        /// <summary>
        /// so luong hinh
        /// </summary>
        private int _nTextures;

        public int nTextures
        {
            get { return _nTextures; }
            set { _nTextures = value; }
        }

      
        private int _iTextures;

        public int iTextures
        {
            get { return _iTextures; }
            set { _iTextures = value; }
        }

        public MySprites2D(Texture2D []Textures, Vector2 position)
        {
            this.Textures = Textures;
            this.Position = position;

        }
        private float _NomalDelay = 25.0f;

        public float NomalDelay
        {
            get { return _NomalDelay; }
            set { _NomalDelay = value; }
        }

        

        public override void Update(GameTime gameTime)
        {
            iTextures = (int)(gameTime.TotalGameTime.Milliseconds/NomalDelay) % nTextures;
            
        }
        public override void Draw(GameTime gameTime,SpriteBatch sp)
        {
 //            for(int i =0;i<nTextures ; i++)
            sp.Begin();
            Rectangle rtg=new Rectangle();
            if (Size.X == 0)
            {
                rtg = new Rectangle((int)Position.X, (int)Position.Y, Textures[iTextures].Width, Textures[iTextures].Height);
                sp.Draw(Textures[iTextures], rtg, Color.White);
            }
            else
            {
                rtg = new Rectangle((int)Position.X, (int)Position.Y,(int)Size.X,(int) Size.Y);
                sp.Draw(Textures[iTextures], rtg, Color.White);
            }
            sp.End();
        }
    }
}
